<template>
  <view class="groupIncomeListMain">
    <view class="groupIncomeListBox">
      <view v-if="list.length > 0">
        <view
          class="groupIncomelistItem"
          v-for="(item, index) in list"
          :key="index"
        >
          <view class="top">
            <view>{{ item.nick_name ? item.nick_name : item.real_name }}</view>
            <view>{{
              $u.timeFormat(item.create_time, "yyyy-mm-dd hh:MM:ss")
            }}</view>
          </view>
          <view class="sub">
            <view class="flex align-center justify-between">
              <text>累计收益(元)</text>
              <text>{{ item.total_income ? item.total_income : "0.00" }}</text>
            </view>
            <view class="flex align-center justify-between">
              <text>本月交易收益(元)</text>
              <text>{{ item.trade_income ? item.trade_income : "0.00" }}</text>
            </view>
            <view class="flex align-center justify-between">
              <text>本月激活收益(元)</text>
              <text>{{
                item.active_income ? item.active_income : "0.00"
              }}</text>
            </view>
          </view>
        </view>
      </view>
      <view
        class="noMachine flex align-center"
        v-if="list.length == 0 && isLoad"
      >
        <image
          src="../../static/images/noData/zwjl.png"
          mode="widthFix"
        ></image>
        <text>暂无收益</text>
      </view>
    </view>
    <u-loadmore
      :status="status"
      @loadmore="loadmore"
      v-if="list.length > 0"
      style="padding: 40rpx 0"
    />
    <toast></toast>
    <u-back-top :scroll-top="scrollTop"></u-back-top>
  </view>
</template>

<script>
export default {
  data() {
    return {
      scrollTop: 0,
      page: 1,
      limit: 10,
      list: [],
      status: "loadmore",
      noMore: false,
      isLoad: false,
    };
  },
  onLoad() {
    this.groupIncomeList();
  },
  onPageScroll(e) {
    this.scrollTop = e.scrollTop;
  },
  onPullDownRefresh() {
    this.page = 1;
    this.list = [];
    this.status = "loadmore";
    this.noMore = false;
    this.isLoad = false;
    this.groupIncomeList();
  },
  onReachBottom() {
    if (this.noMore) {
      this.status = "nomore";
    } else {
      this.status = "loading";
      this.page = ++this.page;
      this.groupIncomeList();
    }
  },
  // 点击下载更多
  loadmore() {
    if (this.noMore) {
      this.status = "nomore";
    } else {
      this.page = ++this.page;
      this.status = "loadmore";
      this.groupIncomeList();
    }
  },
  methods: {
    groupIncomeList() {
      this.$u.api
        .groupIncomeList({
          page: this.page,
          limit: this.limit,
        })
        .then((res) => {
          if (res.status == 200) {
            let datas = res.result;
            if (this.page == 1 && datas.length == 0) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page == 1 && datas.length < this.limit) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page > 1 && datas.length < this.limit) {
              this.noMore == true;
              this.status = "nomore";
            }
            if (this.page > 1 && datas.length == this.limit) {
              this.status = "loading";
            }
            this.list = this.list.concat(datas);
          } else {
            this.$refs.uToast.show({
              title: res.msg,
              type: "error",
              duration: 1200,
            });
          }
          this.isLoad = true;
          uni.stopPullDownRefresh();
        })
        .catch((res) => {
          console.log(res);
          if (res.errMsg == "request:fail timeout") {
            this.$u.toast("请求超时，请重试!");
          } else if (res.errMsg == "request:fail") {
            this.$u.toast("请求失败，请重试");
          } else {
            this.$u.toast(res.resultDesc);
          }
          this.$loading(false);
          setTimeout(() => {
            this.$u.route({
              type: "navigateBack",
              delta: 1,
            });
          }, 2000);
        });
    },
  },
};
</script>

<style lang="scss">
.groupIncomeListMain {
  padding: 30rpx;
  .groupIncomelistItem {
    background: #fff;
    padding: 30rpx;
    margin-bottom: 30rpx;
    border-radius: 10rpx;
    &:last-of-type {
      margin-bottom: 0;
    }
    .top {
      view {
        &:first-of-type {
          font-size: 36rpx;
          font-weight: bold;
        }
        &:nth-of-type(2) {
          padding-top: 10rpx;
        }
      }
    }
    .sub {
      margin-top: 20rpx;
      view {
        line-height: 46rpx;
        text {
          &:nth-of-type(2) {
            font-size: 36rpx;
            color: #fb4535;
            font-family: "numberFont";
          }
        }
      }
    }
  }
}
</style>
